using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace IpMacConfiguratorFramework
{
    public class IpMacEntry
    {
        public string Mac { get; set; }
        public string Ip { get; set; }
        public string Type { get; set; } // "内网" 或 "外网"
        public string Department { get; set; } // 新增字段
        public string User { get; set; } // 新增字段
    }

    public static class IpMacTable
    {
        public static List<IpMacEntry> Entries = new List<IpMacEntry>();
        private const string ResourceName = "IpMacConfiguratorFramework.ip_mac_table.csv";

        public static void LoadFromResource()
        {
            Entries.Clear();
            var assembly = Assembly.GetExecutingAssembly();
            using (var stream = assembly.GetManifestResourceStream(ResourceName))
            {
                if (stream == null)
                {
                    return;
                }
                using (var reader = new StreamReader(stream))
                {
                    reader.ReadLine();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        var parts = line.Split(',');
                        if (parts.Length >= 5)
                        {
                            Entries.Add(new IpMacEntry
                            {
                                Mac = IpMacConfiguratorFramework.NetworkHelper.FormatMac(parts[0].Trim()),
                                Ip = parts[1].Trim(),
                                Type = parts[2].Trim(),
                                Department = parts[3].Trim(),
                                User = parts[4].Trim()
                            });
                        }
                    }
                }
            }
        }

        public static IpMacEntry FindByMac(string mac)
        {
            return Entries.FirstOrDefault(e => e.Mac.Equals(mac, StringComparison.OrdinalIgnoreCase));
        }
    }
} 